package com.monkey.client.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.fastjson.JSON;
import com.monkey.client.MonkeyServerAdressProperties;
import com.monkey.constants.NettyConstants;
import com.monkey.netty.client.NettyClient;
import com.monkey.netty.server.NettyServer;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class ClientConfig {

    @Bean(name = NettyConstants.NETTY_CLIENT)
    @ConditionalOnBean(MonkeyServerAdressProperties.class)
    public NettyClient nettyClient(MonkeyServerAdressProperties monkeyServerAdressProperties) {

        String host = monkeyServerAdressProperties.getIp();
        int port = monkeyServerAdressProperties.getPort();
        log.info("address : {}, {}", host, port);
        int timeOut = monkeyServerAdressProperties.getTimeOut();
        NettyClient nettyClient = new NettyClient(host , port, timeOut);
        return nettyClient;
    }
}
